package cn.tfyhyc.springcloud.service.impl;

import cn.tfyhyc.springcloud.dao.AccountDao;
import cn.tfyhyc.springcloud.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @author 头发又黑又长
 * @Date 2022/10/30 16:26
 * @email zwb15083976291@163.com
 */
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    @Resource
    private AccountDao accountDao;


    @Override
    public void decrease(Long userId, BigDecimal money) {
        log.info("-----------------> account-service中扣减账户余额 开始");
        // 暂停几秒线程,模拟请求超时
//        try { TimeUnit.SECONDS.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); }
        accountDao.decrease(userId, money);
        log.info("-----------------> account-service中扣减账户余额 结束");
    }
}
